<?php
class user extends model {
	
	function login($name, $password) {
		if (empty($name) || empty($password)) {
			return false;
		}
		
		$this->loadByField("name", $name);
		
		if ($this->name == $name && $this->password == $password) {
			request::set("user", $name, "session");
			return true;
		} else {
			return false;
		}
	}
	
	function logout() {
		request::set("user", false, "session");
	}
	
	function loadFromSession() {
		if ($username = request::get("user", "session")) {
			return $this->loadByField("name", $username);
		} else {
			return false;
		}
	}
	
}
?>